home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / gadgets.lzh / Gadgets / Example11.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  8KB  |  211 lines

  1. /* Example11                                                          */
  2. /* This program will open a normal window which is connected to the   */
  3. /* Workbench Screen. The window will use all System Gadgets, and will */
  4. /* close first when the user has selected the System gadget Close     */
  5. /* window. Inside the window we have put a Proportional gadget where  */
  6. /* the knob can be moved both horizontally and vertically.            */
  7.  
  8.  
  9.  
  10. #include <intuition/intuition.h>
  11.  
  12.  
  13.  
  14. struct IntuitionBase *IntuitionBase;
  15.  
  16.  
  17.  
  18. /* THE PROPORTIONAL GADGET's STRUCTURES: */
  19.  
  20. /* We need to declare an Image structure for the knob, but since */
  21. /* Intuition will take care of the size etc of the knob, we do not need */
  22. /* to initialize the Image structure: */
  23. struct Image my_image;
  24.  
  25.  
  26. struct PropInfo my_prop_info=
  27. {
  28.   FREEHORIZ|      /* Flags, the knob should be able to movew both */
  29.   FREEVERT|       /* horizontally and vertically. */
  30.   AUTOKNOB,       /* Intuition should take care of the knob image. */
  31.   0,              /* HorizPot, start position of the knob. */
  32.   0,              /* VertPot, start position of the knob. */
  33.   MAXBODY * 1/32, /* HorizBody, 32 steps. */
  34.   MAXBODY * 1/10, /* VertBody, 10 steps. */
  35.  
  36.   /* These variables are initialized and maintained by Intuition: */
  37.  
  38.   0,              /* CWidth */
  39.   0,              /* CHeight */
  40.   0, 0,           /* HPotRes, VPotRes */
  41.   0,              /* LeftBorder */
  42.   0               /* TopBorder */
  43. };
  44.  
  45.  
  46. struct Gadget my_gadget=
  47. {
  48.   NULL,            /* NextGadget, no more gadgets in the list. */
  49.   10,              /* LeftEdge, 10 pixels out. */
  50.   20,              /* TopEdge, 20 lines down. */
  51.   -20,             /* Width, always 20 pixels less than the wind. size. */
  52.   -40,             /* Height, always 40 lines less than the wind. size. */
  53.   GADGHCOMP|       /* Flags, complement the colours. */
  54.   GRELWIDTH|       /* Width describes the size relative to the window. */
  55.   GRELHEIGHT,      /* Height describes the size relative to the window*/
  56.   GADGIMMEDIATE|   /* Activation, our program will recieve a message */
  57.   RELVERIFY,       /* when the user has selected this gadget, and when */
  58.                    /* the user has released it. */ 
  59.   PROPGADGET,      /* GadgetType, a Proportional gadget. */
  60.   (APTR) &my_image,/* GadgetRender, a pointer to our Image structure. */
  61.                    /* (Intuition will take care of the knob image) */
  62.                    /* (See chapter 3 GRAPHICS for more information) */
  63.   NULL,            /* SelectRender, NULL since we do not supply the */
  64.                    /* gadget with an alternative image. */
  65.   NULL,            /* GadgetText, no text. */
  66.   NULL,            /* MutualExclude, no mutual exclude. */
  67.   (APTR) &my_prop_info, /* SpecialInfo, pointer to a PropInfo structure. */
  68.   0,               /* GadgetID, no id. */
  69.   NULL             /* UserData, no user data connected to the gadget. */
  70. };
  71.  
  72.  
  73.  
  74. /* Declare a pointer to a Window structure: */ 
  75. struct Window *my_window;
  76.  
  77. /* Declare and initialize your NewWindow structure: */
  78. struct NewWindow my_new_window=
  79. {
  80.   50,            /* LeftEdge    x position of the window. */
  81.   25,            /* TopEdge     y positio of the window. */
  82.   320,           /* Width       320 pixels wide. */
  83.   100,           /* Height      100 lines high. */
  84.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  85.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  86.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  87.                  /*             user has selected the Close window gad, */
  88.   GADGETDOWN|    /*             or a gadget has been pressed on, or */
  89.   GADGETUP,      /*             a gadge has been released. */
  90.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  91.   WINDOWCLOSE|   /*             Close Gadget. */
  92.   WINDOWDRAG|    /*             Drag gadget. */
  93.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  94.   WINDOWSIZING|  /*             Sizing Gadget. */
  95.   ACTIVATE,      /*             The window should be Active when opened. */
  96.   &my_gadget,    /* FirstGadget A pointer to the String gadget. */
  97.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  98.   "Proportional Window", /* Title Title of the window. */
  99.   NULL,          /* Screen      Connected to the Workbench Screen. */
  100.   NULL,          /* BitMap      No Custom BitMap. */
  101.   100,           /* MinWidth    We will not allow the window to become */
  102.   100,           /* MinHeight   smaller than 100 x 100, and not bigger */
  103.   640,           /* MaxWidth    than 640 x 200. */
  104.   200,           /* MaxHeight */
  105.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  106. };
  107.  
  108.  
  109.  
  110. main()
  111. {
  112.   /* Boolean variable used for the while loop: */
  113.   BOOL close_me;
  114.  
  115.   /* Declare a variable in which we will store the IDCMP flag: */
  116.   ULONG class;
  117.  
  118.   /* Declare a pointer to an IntuiMessage structure: */
  119.   struct IntuiMessage *my_message;
  120.  
  121.  
  122.  
  123.   /* Before we can use Intuition we need to open the Intuition Library: */
  124.   IntuitionBase = (struct IntuitionBase *)
  125.     OpenLibrary( "intuition.library", 0 );
  126.   
  127.   if( IntuitionBase == NULL )
  128.     exit(); /* Could NOT open the Intuition Library! */
  129.  
  130.  
  131.  
  132.   /* We will now try to open the window: */
  133.   my_window = (struct Window *) OpenWindow( &my_new_window );
  134.   
  135.   /* Have we opened the window succesfully? */
  136.   if(my_window == NULL)
  137.   {
  138.     /* Could NOT open the Window! */
  139.     
  140.     /* Close the Intuition Library since we have opened it: */
  141.     CloseLibrary( IntuitionBase );
  142.  
  143.     exit();  
  144.   }
  145.  
  146.  
  147.  
  148.   /* We have opened the window, and everything seems to be OK. */
  149.  
  150.  
  151.  
  152.   close_me = FALSE;
  153.  
  154.   /* Stay in the while loop until the user has selected the Close window */
  155.   /* gadget: */
  156.   while( close_me == FALSE )
  157.   {
  158.     /* Wait until we have recieved a message: */
  159.     Wait( 1 << my_window->UserPort->mp_SigBit );
  160.  
  161.     /* We have now recieved one or more messages. */
  162.  
  163.     /* Since we may recieve several messages we stay in the while loop */
  164.     /* and collect, save, reply and execute the messages until there is */
  165.     /* a pause: */
  166.     while(my_message=(struct IntuiMessage *)GetMsg( my_window->UserPort))
  167.     {
  168.       /* GetMsg will return a pointer to a message if there was one, */
  169.       /* else it returns NULL. We will therefore stay in this while loop */
  170.       /* as long as there are some messages waiting in the port. */
  171.       
  172.       /* After we have collected the message we can read it, and save */
  173.       /* any important values which we maybe want to check later: */
  174.       class = my_message->Class;      /* Save the IDCMP flag. */
  175.  
  176.       /* After we have read it we reply as fast as possible: */
  177.       /* REMEMBER! Do never try to read a message after you have replied! */
  178.       /* Some other process has maybe changed it. */
  179.       ReplyMsg( my_message );
  180.  
  181.       /* Check which IDCMP flag was sent: */
  182.       switch( class )
  183.       {
  184.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  185.                close_me=TRUE;
  186.                break;
  187.              
  188.         case GADGETDOWN:   /* The user has selected the Prop. gadget: */
  189.                printf("Proportional gadget selected.\n");
  190.                break;
  191.              
  192.         case GADGETUP:     /* The user has released the Prop. gadget: */
  193.                printf("Proportional gadget released.\n");
  194.                break;
  195.       }
  196.     }
  197.     printf("Hor= %1.0f\n", (float) my_prop_info.HorizPot / MAXPOT * 32);
  198.     printf("Ver= %1.0f\n\n", (float) my_prop_info.VertPot / MAXPOT * 10);
  199.   }
  200.  
  201.   /* We should always close the windows we have opened before we leave: */
  202.   CloseWindow( my_window );
  203.  
  204.  
  205.  
  206.   /* Close the Intuition Library since we have opened it: */
  207.   CloseLibrary( IntuitionBase );
  208.  
  209.   /* THE END */
  210. }
  211.